<script setup name="podcast">
import { ref, onMounted } from 'vue'
import { HamburgerButton, AddOne } from '@icon-park/vue-next'
import { personalizedDjprogram, personalize } from '@/services/podcast'
import { formartNum } from '@/utils/util'
import Search from '@/components/common/Search.vue'
import IconPark from '@/components/common/IconPark.vue'

const active = ref('推荐')
const programList = ref([])
const personalizeList = ref([])

const initData = async () => {
  const { result } = await personalizedDjprogram()
  const { data } = await personalize()
  programList.value = result
  personalizeList.value = data
}
onMounted(() => initData())
</script>

<template>
  <main class="podcast-page">
    <van-tabs v-model:active="active" swipeable sticky line-width="20px" color="red"
      background="var(--reversal-singer-main)">
      <template #nav-left>
        <IconPark :icon="HamburgerButton" :size="7" :strokeWidth="3" style="padding-left:6px;" />
      </template>
      <template #nav-right>
        <IconPark :icon="AddOne" :size="7" :strokeWidth="3" theme="filled" fill="red" style="padding-right:6px;" />
      </template>
      <template #nav-bottom>
        <div class="nav-bottom">
          <Search :showScanCode="false" />
        </div>
      </template>
      <van-tab title="推荐" class="podcast-page-tab">
        <div class="program">
          <div class="more">
            <h3>为你推荐的专属播客</h3>
          </div>
          <van-row gutter="24" justify="center" v-for="item in programList" :key="item.id">
            <van-col span="6">
              <van-image radius="10" :src="item.picUrl" />
            </van-col>
            <van-col span="18">
              <div class="copywriter">{{ item.copywriter }}</div>
              <div class="name">{{ item.name }}</div>
              <div class="playCount">{{ formartNum(item.program.adjustedPlayCount) }}</div>
            </van-col>
          </van-row>
        </div>
        <div class="program">
          <div class="more">
            <h3>宝藏播客</h3>
          </div>
          <van-row gutter="24" justify="center" v-for="item in personalizeList" :key="item.id">
            <van-col span="6">
              <van-image radius="10" :src="item.picUrl" />
            </van-col>
            <van-col span="18">
              <div class="desc">{{ item.desc }}</div>
              <div class="name">{{ item.name }}</div>
            </van-col>
          </van-row>
        </div>
      </van-tab>
      <van-tab title="有声书" class="podcast-page-tab">
        有声书
      </van-tab>
      <van-tab title="广播剧" class="podcast-page-tab">
        广播剧
      </van-tab>
      <van-tab title="听听" class="podcast-page-tab">
        听听
      </van-tab>
    </van-tabs>

  </main>
</template>

<style scoped lang="scss">
.podcast-page {
  .nav-bottom {
    background: var(--reversal-singer-main);
    padding: 10px 0;
    border-top: 1px solid var(--reversal-singer-main);
  }

  .program {
    .more {
      padding: 10px;

      h3 {
        font-size: 18px;
      }
    }
  }

  .i-icon-hamburger-button {
    padding: 6px 0 0 6px;
  }

  .i-icon-add-one {
    padding: 6px 6px 0 0;
  }

  :deep(.van-tabs__nav--line) {
    justify-content: center;
    align-items: center;
  }

  :deep(.van-tabs__line) {
    bottom: 6vw;
  }

  :deep(.van-tab--active) {
    color: var(--reversal-text);
  }
}
</style>
